package com.yc.chaoshi.cs_manage.mapper;

import com.yc.chaoshi.entity.PmsGoods;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xz
 * @since 2022-08-04
 */
public interface PmsGoodsMapper extends BaseMapper<PmsGoods> {

//    @Select("select id,oid,name,points," +
//            " image,image_album,grd,sgrd," +
//            " sales,stock,price,discount_price," +
//            " amount from pms_goods WHERE del=1" +
//            " limit #{page}, 10")
//    List<PmsGoods> queryGoods(@Param("page")int page);

    List<PmsGoods> selectGoods(@Param("name")String name,
                               @Param("oid")int oid,
                               @Param("page")int page,
                               @Param("size") int size );
    @Select("select count(*) from pms_goods a " +
            "LEFT JOIN pms_fenlei3 b on a.oid = b.cid " +
            "WHERE del=1 and name LIKE CONCAT('%', #{name}, '%') and cid = #{cid}")
    String queryGoodsCount(@Param("name")String name,
                            @Param("cid")int cid);

    @Insert("insert into pms_goods values (default,#{oid},#{name},#{points},#{image},#{image_album}," +
            " #{del},#{grd},#{sgrd},#{sales}," +
            " #{stock},0,#{price},#{discount_price},null,'',null)")
    Long insertGood(@Param("oid")int oid, @Param("name")String name,
                    @Param("points")int points, @Param("image")String image,
                    @Param("image_album")String image_album, @Param("del")int del,
                    @Param("grd")int grd, @Param("sgrd")int sgrd,
                    @Param("sales")int sales, @Param("stock")int stock,
                    @Param("price")double price, @Param("discount_price")double discount_price);

    @Update("update pms_goods set oid=#{oid},name=#{name},points=#{points},image=#{image}," +
            "image_album=#{image_album},del=#{del},grd=#{grd},sgrd=#{sgrd}," +
            " sales=#{sales},stock=#{stock},price=#{price},discount_price=#{discount_price} where id=#{id}")
    Long updateGood(@Param("oid")int oid, @Param("name")String name,
                    @Param("points")int points, @Param("image")String image,
                    @Param("image_album")String image_album, @Param("del")int del,
                    @Param("grd")int grd, @Param("sgrd")int sgrd,
                    @Param("sales")int sales, @Param("stock")int stock,
                    @Param("price")double price, @Param("discount_price")double discount_price,
                    @Param("id") int id);
}
